﻿using System;
using System.Net;
using System.Net.Mail;
using MefBasic.Threading;

namespace MediaAssistant.Helper
{
    public class EMailHelper
    {
        private const string SmtpServer = "smtp.gmail.com";
        private const string SmtpUsername = "hsmasud.contact@gmail.com";
        private const string Password = "E9Ojp3kdjabkrtcOcde4";
        private const string ContactEMail = "hsmasud@gmail.com";

        public static void Send(string from, string subject, string message)
        {
            var worker = new BackgroundWorkerEx();
            worker.DoWork += (s, e) =>
                                 {
                                     try
                                     {
                                         var client = new SmtpClient(SmtpServer, 587)
                                         {
                                             Credentials = new NetworkCredential(SmtpUsername, Password),
                                             EnableSsl = true
                                         };
                                         var mailMessage = new MailMessage(from, ContactEMail, subject, message);
                                         mailMessage.ReplyToList.Add(from);
                                         client.Send(mailMessage);
                                     }
                                     catch (Exception ex)
                                     {
                                         e.Result = ex;
                                     }

                                 };
            worker.RunWorkerBlocked();
            
       }
    }
}
